<template>
    <div>
      <div>{{ num }}</div>
      <button @click="increment">+</button>
    </div>
  </template>
  <script lang="ts" setup>
  import { ref, watch } from "vue";
  //1、定义一个ref变量
  let num = ref<number>(0);
  //2、定义一个更新变量的函数
  const increment = () => num.value++;
  //3、使用watch侦听器来完成对ref变量的侦听
  watch(num, (newval, oldval) => {
    console.log(newval, oldval);
  });
  </script>
  
  <style lang="scss" scoped></style>
  